package com.leet.meituan;

import java.util.*;

public class NoWay {
    private static List<List<Integer>> adj;
    private static Map<Integer,Integer> map;
    public static void main(String[] args) {
        int ans = -1;
        adj = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int pos_x = Integer.parseInt(s[1]);
        int pos_y = Integer.parseInt(s[2]);
        for(int i = 0; i < n; ++i){
            adj.add(new ArrayList<>());
        }
        for(int i = 1; i < n; ++i){
            String[] connection = sc.nextLine().split(" ");
            adj.get(Integer.parseInt(connection[0])).add(Integer.parseInt(connection[1]));
            adj.get(Integer.parseInt(connection[1])).add(Integer.parseInt(connection[0]));
        }
        Map<Integer,Integer> map1 = new HashMap<>();
        Map<Integer,Integer> map2 = new HashMap<>();
        boolean[] vis1 = new boolean[n+1];
        boolean[] vis2 = new boolean[n+1];
        bfs(map1,pos_x,vis1);
        bfs(map2,pos_y,vis2);
        for(Map.Entry<Integer,Integer> entry:map1.entrySet()){
            int goal = entry.getKey();
            int dis1 = entry.getValue();
            int dis2 = map2.get(goal);
            ans = Integer.max(ans,Math.abs(dis1-dis2));
        }
        System.out.println(ans);
    }
    static void bfs(Map<Integer,Integer> map,int pos,boolean[] visited){
        Queue<Integer> q = new LinkedList<>();
        q.add(pos);
        int len = 0;
        while(!q.isEmpty()){
            int size = q.size();
            for (int i = 0; i < size; ++i){
                Integer head = q.poll();
                // 所有点都记录
                map.put(pos,len);
                visited[head] = true;
                for(Integer neigh:adj.get(head)){
                    if(!visited[neigh]){
                        q.add(neigh);
                    }
                }
            }
            len++;
        }
    }
}
